/**
 * 
 */
package current;

import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import monitor.Button1Listener;
import monitor.DataGet;

/**
 * @Description:  
 * @version: v1.0.0
 * @author: wbl
 * @date: 2019年10月29日 上午10:55:51
 */
public class DataAcquisitionThread implements Runnable{

 	private static String code;
    private static double monitor0;
    private static double monitor1;
    public static double currentPrice;
    
    private JTextArea resultArea;//视图显示结果
    private JTextField textFieldA;//输入的边
    private JTextField textFieldB;
    private JTextField textFieldC;

    public static boolean flag = true;
    
	public static String getCode() {
		return code;
	}



	public static void setCode(String code) {
		DataAcquisitionThread.code = code;
	}



	public static double getMonitor0() {
		return monitor0;
	}



	public static void setMonitor0(double monitor0) {
		DataAcquisitionThread.monitor0 = monitor0;
	}



	public static double getMonitor1() {
		return monitor1;
	}



	public static double getCurrentPrice() {
		return currentPrice;
	}



	public static void setCurrentPrice(double currentPrice) {
		DataAcquisitionThread.currentPrice = currentPrice;
	}



	public static void setMonitor1(double monitor1) {
		DataAcquisitionThread.monitor1 = monitor1;
	}
	
	
	
	public JTextArea getResultArea() {
		return resultArea;
	}



	public void setResultArea(JTextArea resultArea) {
		this.resultArea = resultArea;
	}



	public JTextField getTextFieldA() {
		return textFieldA;
	}



	public void setTextFieldA(JTextField textFieldA) {
		this.textFieldA = textFieldA;
	}



	public JTextField getTextFieldB() {
		return textFieldB;
	}



	public void setTextFieldB(JTextField textFieldB) {
		this.textFieldB = textFieldB;
	}



	public JTextField getTextFieldC() {
		return textFieldC;
	}



	public void setTextFieldC(JTextField textFieldC) {
		this.textFieldC = textFieldC;
	}



	/**
	 * @Description:
	 */
	public DataAcquisitionThread(String code,double monitor0,double monitor1) {
        this.code=code;
        this.monitor0=monitor0;
        this.monitor1=monitor1;
	}

	
	

	@Override
	public void run() {
		while(flag) {
			DataGet price = new DataGet();
	    	price.setCode(code);
	    	String currentPrice = price.getCurrentPrice();//最新价格
	    	double cpri = Double.parseDouble(currentPrice);
	    	if(monitor0 >= cpri) {//当前价格小于设置的最低值
	    		JOptionPane.showMessageDialog(null, "设置底价："+monitor0+"---当前价格:"+currentPrice,
	    				 "下滑价超预警提示", JOptionPane.YES_NO_OPTION);
	    		flag = false;
//	    		MultithreadProcessing.recvAtuoTaskThreadPool.shutdown();
//	    		MultithreadProcessing.recvAtuoTaskThreadPool = null;
	    		System.exit(0);
	    	}else if(monitor1 <= cpri){//当前价格已高于设置的最高限值
	    		JOptionPane.showMessageDialog(null, "设置高价："+monitor0+"---当前价格:"+currentPrice,
	    				 "上涨价超预警提示", JOptionPane.YES_NO_OPTION);
	    		flag = false;
//	    		MultithreadProcessing.recvAtuoTaskThreadPool.shutdown();
//	    		MultithreadProcessing.recvAtuoTaskThreadPool = null;
	    		System.exit(0);
	    	}
	    	
//	    	resultArea.setCaretPosition(resultArea.getText().length());//滚动条获取焦点，不加不自动滚

	        
	    	resultArea.append("当前价格："+currentPrice+"\n");
	    	resultArea.paintImmediately(resultArea.getBounds());//实时
	    	
	    	try {
				Thread.sleep(2000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
	

}
